<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('月评价结果列表')"/>
</head>
<style>
    .layui-table-cell {
        height: auto !important;
        line-height: 34px !important;
    }

    th .layui-table-cell {
        font-size: 12px !important;
    }
    .layui-table td, .layui-table th {
        font-size: 12px !important;
    }

</style>
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
        <form action="" class="layui-form">
            <div class="layui-form-item">
                <button class="pear-btn pear-btn-group pear-btn-warming"
                        lay-filter="export" lay-submit type="button">
                    <i class="layui-icon layui-icon-export"></i>
                    导出
                </button>
            </div>
        </form>
    </div>
</div>

<div class="layui-card">
    <div class="layui-card-body">
        <table id="viewResult-table" lay-filter="viewResult-table"></table>
    </div>
</div>
</body>

<script type="text/html" id="viewResult-type">
    {{#if (d.dataState == '0') { }}
    <span class="layui-badge layui-bg-orange">开启</span>
    {{# }else if(d.dataState == '-1'){ }}
    <span class="layui-badge layui-bg-blue">关闭</span>
    {{# } }}
</script>

<th:block th:include="include :: footer"/>
<script th:inline="javascript" type="text/javascript">

    /*<![CDATA[*/
    var taskMonth = /*[[${taskMonth}]]*/ 20;
    /*]]>*/

    console.log(taskMonth);

    layui.use(['table', 'form', 'jquery'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;

        var MODULE_PATH = rootPath + "/MonthResultController/";
        var cols = [
            [

                {title: '排名', field: 'finalrank', align: 'center', width: 80},

                {title: '任务年月', field: 'taskMonth', align: 'center', width: 80},

                {title: '供电所名称', field: 'supplyName', align: 'center', width: 130},

                // {title: '所属分公司', field: 'orgnizationName', align: 'center', width: 220},

                {
                    field: 'star', title: '供电所星级', align: 'center', width: 100 ,templet: function (res) {
                        if (res.star == '1') {
                            return '一星';
                        } else if (res.star == '2') {
                            return '二星';
                        } else if (res.star == '3') {
                            return '三星';
                        } else if (res.star == '4') {
                            return '四星';
                        } else if (res.star == '5') {
                            return '五星';
                        } else {
                            return '';
                        }
                    }
                },

                {
                    title: '一、营销服务<br/>（20%）', field: 'yingxiaoScore', align: 'center', width: 110, templet: function (res) {
                        return redline(res.yingxiaoScore, res.star)
                    }
                },

                {
                    title: '二、运维抢修<br/>（20%）', field: 'yunjianScore', align: 'center', width: 110, templet: function (res) {
                        return redline(res.yunjianScore, res.star)
                    }
                },

                {
                    title: '三、安全管理<br/>（15%）', field: 'anquanScore', align: 'center', width: 110, templet: function (res) {
                        return redline(res.anquanScore, res.star)
                    }
                },

                {
                    title: '四、党建及<br/>队伍建设<br/>（15%）', field: 'dangjianScore', align: 'center', width: 120, templet: function (res) {
                        return redline(res.dangjianScore, res.star)
                    }
                },

                {
                    title: '五、数字化转型<br/>（10%）', field: 'shuzihuaScore', align: 'center', width: 120, templet: function (res) {
                        return redline(res.shuzihuaScore, res.star)
                    }
                },

                {
                    title: '六、发展规划<br/>（10%）', field: 'fazhanScore', align: 'center', width: 110, templet: function (res) {
                        return redline(res.fazhanScore, res.star)
                    }
                },

                {
                    title: '七、“五小”建设<br/>及基础保障<br/>（10%）', field: 'wuxiaoScore', align: 'center', width: 130, templet: function (res) {
                        return redline(res.wuxiaoScore, res.star)
                    }
                },

                {title: '总得分<br/>(未加权)', field: 'totalMark', align: 'center', width: 100},

                {title: '总得分<br/>(权重计算)', field: 'totalScore', align: 'center', width: 100},

                {
                    field: 'isNeccessary', title: '必备条件<br/>是否合格', align: 'center', width: 100, templet: function (res) {
                        if (res.isNeccessary == '0') {
                            return '<div style="background-color:#ff7777; width: 100%; height: 100%;"><a class=""style="color:#fff">否</a></div>';
                        } else if (res.isNeccessary == '1') {
                            return '是';
                        } else if (res.isNeccessary == '2') {
                            return '结果上报中';
                        }
                    }
                },

                {
                    field: 'isIssue', title: '结果是否<br/>发布完成', align: 'center', width: 100, templet: function (res) {
                        if (res.isIssue == '0') {
                            return '否';
                        } else if (res.isIssue == '1') {
                            return '是';
                        } else if (res.isIssue == '2') {
                            return '结果上报中';
                        }
                    }
                }
            ]
        ]

        //table表单列表
        table.render({
            elem: '#viewResult-table',
            url: MODULE_PATH + 'list4currentResult/' + taskMonth,
            page: true,
            method: 'get',
            cols: cols,
            skin: 'line',
            limit: 80,
            toolbar: '#viewResult-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }]
        });

        // 定义函数
        function redline(score, star) {
            console.log(score);
            var target = '';
            if (star == 5) {
                target = 90
            } else if (star == 4) {
                target = 85
            } else if (star == 3) {
                target = 80
            }
            if (score !== null && score !== "" && score !== "null") {
                if (score < target) {
                    return '<div style="background-color:#ff7777; width: 100%; height: 100%;"><a class=""style="color:#fff">' + score + '</a></div>';
                } else {
                    return score;
                }
            } else {
                return "";
            }

        }

        //table工具栏绑定
        table.on('toolbar(viewResult-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });


        //刷新按钮
        window.refresh = function () {
            table.reload('viewResult-table');
        }

        //导出
        form.on('submit(export)', function (data) {
            var now = getnow();
            var url = rootPath + '/AgencyStyleExportController/agencyStyleExport1?taskMonth=' + taskMonth
            downloadFile(url, taskMonth+"月度实时评价结果"+now+".xls");
        });

        function getnow(){
            var myDate = new Date();	//创建Date对象
            var Y = myDate.getFullYear();   //获取当前完整年份
            var M = myDate.getMonth() + 1;  //获取当前月份
            var D = myDate.getDate();   //获取当前日1-31
            var H = myDate.getHours();  //获取当前小时
            var i = myDate.getMinutes();    //获取当前分钟
            var s = myDate.getSeconds();    //获取当前秒数
            // 月份不足10补0
            if(M < 10){
                M = '0' + M;
            }
            // 日不足10补0
            if(D < 10){
                D = '0' + D;
            }
            // 小时不足10补0
            if(H < 10){
                H = '0' + H;
            }
            // 分钟不足10补0
            if(i < 10){
                i = '0' + i;
            }
            // 秒数不足10补0
            if(s < 10){
                s = '0' +s;
            }
            // 拼接日期分隔符根据自己的需要来修改
            var nowDate = M+'月'+D+'日 '+H+'时'+i+'分'+s+'秒';
            return nowDate;
        }
    })


</script>
</html>